package letcode.commonOrder.$1$two_sum;

import java.util.ArrayList;
import java.util.List;

/**
 * ��Ȼ��ʹ�ñ�����
 * @author app2
 *
 */
public class TwoSum1 {
	public static void main(String[] args) {
		int[] nums = { 2, 7, 11, 15, 4, 5 };
		int target = 9;
		List print = twoSum(nums, target);
		for (int i = 0; i < print.size(); i = i + 2)
			System.out.println("[" + print.get(i) + "," + print.get(i + 1) + "]");
	}

	/**
	 * �ҳ�����֮��
	 * 
	 * @param nums
	 * @param target
	 * @return
	 */
	public static List twoSum(int[] nums, int target) {
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < nums.length; i++) {
			for (int j = i + 1; j < nums.length; j++) {
				if (nums[j] == target - nums[i]) {
					list.add(i);
					list.add(j);
				}
			}
		}
		if (list.size() <= 0)
			throw new IllegalArgumentException("No two sum solution");
		else
			return list;

	}
}

/*
 * ���������
 */
